package com.wind.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wind.common.annotation.TraceLog;
import com.wind.common.dto.TestDTO;
import com.wind.common.query.TestQuery;
import com.wind.common.utils.ThreadPoolUtil;
import com.wind.common.vo.TestVO;
import com.wind.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;

/**
 * @author FengYin
 * @since 2024/8/30 18:09
 */
@Service
@Slf4j
public class TestServiceImpl implements TestService {

    @Override
    @TraceLog
    public void add(TestDTO dto) {
        log.info("add");
        for (int i = 0; i < 10; i++) {
            Future<Long> future = ThreadPoolUtil.submit(() -> {
                log.info("线程池执行");
                return 2 / dto.getId();
            });
            try {
                Long l = future.get();
            } catch (Exception e) {
//                throw new RuntimeException(e);
            }
        }


    }

    @Override
    @TraceLog
    public void edit(TestDTO dto) {
        return;
    }

    @Override
    public List<TestVO> list(TestQuery query) {
        List<TestVO> voList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            TestVO vo = BeanUtil.copyProperties(query, TestVO.class);
            vo.setId((long) i);
            vo.setName("测试" + i);
            voList.add(vo);
        }
        return voList;
    }

    @Override
    public TestVO info(Long id) {
        TestVO vo = new TestVO();
        vo.setId(id);
        vo.setName("测试" + id);
        return vo;
    }
}
